package net.tuandn.training.lesson.gson;

import net.tuandn.training.model.City;
import net.tuandn.training.model.Country;

import com.google.gson.ExclusionStrategy;
import com.google.gson.FieldAttributes;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class ClazzExcluder {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		GsonBuilder gsonBuilder = new GsonBuilder();
		gsonBuilder.addSerializationExclusionStrategy(new ExclusionStrategy() {

			public boolean shouldSkipField(FieldAttributes f) {
				return false;
			}

			public boolean shouldSkipClass(Class<?> clazz) {
				if (clazz.equals(City.class)) {
					return true;
				}
				return false;
			}
		});
		Gson gson = gsonBuilder.setPrettyPrinting().create();
		City hanoi = new City(4, "Hanoi", 4000);
		Country vietnam = new Country("vnm", "Vietnam", "Viet Nam", 1945, hanoi);
		System.out.println(gson.toJson(vietnam));
	}
}
